package com.runa.monitor.platinterface.extend.nb.utils;

import com.runa.protocol.util.UtilTime;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author: lyd
 * @Description: mqtt设置帮助类
 * @Date: 2021/7/8 13:24
 * @Version: 1.0
 */
public class NewMqttSetUtils {

    private static final Logger logger = LoggerFactory.getLogger(NewMqttSetUtils.class);

    /**
     * 应用key
     */
    public static String APP_KEY = "JKzyqBKxqHj";
    /**
     * 应用秘钥
     */
    public static String APP_SECRET = "qhalA8N65C";
    /**
     * 小瑞面板产品id
     */
    public static String RUI_PANEL_PRODUCT_ID = "15002405";
    /**
     * 楼阀-Master-APIkey
     */
    public static String RUI_PANEL_MASTER_KEY = "f50273530e0c41548447b9ccd89fb1cf";


    /**
     * 校时时差（毫秒）
     */
    public static final int CHECK_TIME_SECOND = 6000;


    public static final String MBCX = "面板分离";

    /**
     * 检查唤醒周期是否超过 24小时30分钟
     * true:能发送  false:不能发送
     */
    public static boolean checkCanSendWakeUpCycle(Date addTime) {
        Date temp = UtilTime.addMinute(addTime, 1470);
        return System.currentTimeMillis() <= temp.getTime();
    }


    /**
     * 根据类型获取工厂名称
     *
     * @param type 类型
     * @return 工厂名称
     */
    public static String getFactoryNameByType(String type) {
        if ("1".equals(type)) {
            return "瑞纳";
        }
        return null;
    }

//    public static void main(String[] args) {
//        SendCmdConfigVo sendCmdConfigVo = new SendCmdConfigVo();
//        sendCmdConfigVo.setDeviceId("5d432d078a634d5081ff944c09d1b226");
//        sendCmdConfigVo.setProductId("15002405");
//        sendCmdConfigVo.setAppKey(APP_KEY);
//        sendCmdConfigVo.setAppSecret(APP_SECRET);
//        sendCmdConfigVo.setMasterKey("f50273530e0c41548447b9ccd89fb1cf");
//        sendDownCommand(sendCmdConfigVo, null);
//    }


    /**
     * 解析参数
     *
     * @param responseContent 响应内容
     * @return map 返回结果
     */
    public static Map<String, String> getParsingArgumentsMap(String responseContent) {
        Map<String, String> hashMap = null;
        if (StringUtils.isNotBlank(responseContent)) {
            String[] array = responseContent.split(",");
            hashMap = new HashMap<>();
            for (String string : array) {
                if (StringUtils.isNotBlank(string)) {
                    String[] itemArray = string.split(":");
                    if (itemArray.length >= 2) {
                        String key = itemArray[0];
                        String value = itemArray[1];
                        if (StringUtils.isNotBlank(key) && StringUtils.isNotBlank(value)) {
                            hashMap.put(key.trim(), value.trim());
                        }
                    }
                }
            }
        }
        return hashMap;
    }
}
